package org.rufolfheszele.andpixelbyandpixel;

import java.io.IOException;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

/**
 * Helper class to draw the logo on the window
 *
 * @see StaticDrawController
 * @author Rudolf Heszele heszele@gmail.com
 * @version 1.0
 * @since 2012-03-08
 */
public class LogoDrawController extends StaticDrawController
{
		/**
		 * The default constructor can take two parameters at the beginning of the game
		 *
		 * The optionally arguments are taken only when the application is started, because in this case the MainPanel can not be reached through
		 * the wxGetApp method, since the window itself is not constructed yet by the wxWidgets, and the cache needs to be reset before repainting
		 * @param mainPanel If not null it is used to trigger a refresh
		 * @param resetCache If true the cached configuration parameters are cleared before drawing
		 */
		public LogoDrawController(MainImageView mainImageView, boolean resetCache)
		{
			super(null, false);
			
			try
			{
				// Read the logo, and make it mutable
				Bitmap logo = BitmapFactory.decodeStream(MainApplication.getMainApplication().getMainActivity().getResources().getAssets().open(MainApplication.getMainApplication().getConfiguration().getLogoPath()));
				this.setBitmap(logo.copy(logo.getConfig(), true));
			}
			catch (IOException exception)
			{
				// Nothing to do yet
			}
			// Reset the cache in the configuration if requested - mainly when a game is finished
			if(true == resetCache)
				MainApplication.getMainApplication().getConfiguration().resetCache(true);
			this.refreshImage(true, mainImageView);
		}
};